package com.suning.framework.ImportMpsInfo;

import com.suning.framework.Dao;
import com.suning.framework.Mps_member_portrait_info;
import org.apache.commons.lang.exception.ExceptionUtils;
import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;

import java.util.List;

/**
 * 〈一句话功能简述〉<br>
 * 〈功能详细描述〉
 *
 * @author 16080951(林健)
 * @Copyright (c) 2016 苏宁软件技术有限公司 版权所有
 * @see [相关类/方法]（可选）
 * @since [产品/模块版本] （可选）
 */
public class TestRunnable implements Runnable {

    private static  ApplicationContext applicationContext = new ClassPathXmlApplicationContext("config/application.xml");
    private Dao dao = (Dao) applicationContext.getBean("dao");

    private ImportMps importMps = new ImportMps();
    private int startPage;

    private int endPage;

    public int getStartPage() {
        return startPage;
    }

    public void setStartPage(int startPage) {
        this.startPage = startPage;
    }

    public int getEndPage() {
        return endPage;
    }

    public void setEndPage(int endPage) {
        this.endPage = endPage;
    }

    /**
     * When an object implementing interface <code>Runnable</code> is used
     * to create a thread, starting the thread causes the object's
     * <code>run</code> method to be called in that separately executing
     * thread.
     * <p>
     * The general contract of the method <code>run</code> is that it may
     * take any action whatsoever.
     *
     * @see Thread#run()
     */
    @Override
    public void run() {
        //synchronized (this){
            try {
                //System.out.println("<----start:"+getStartPage()+","+getEndPage()+"----->");
                List<Mps_member_portrait_info> list = dao.queryForPage(startPage,endPage);
                importMps.setInfo(list);
                System.out.println(getStartPage()+"----"+getEndPage()+"结束了");
                //System.out.println("<----end:"+getStartPage()+","+getEndPage()+"----->");

            } catch (Exception e) {
                e.printStackTrace();
                System.out.println(getStartPage()+"----"+getEndPage()+"异常了"+ ExceptionUtils.getFullStackTrace(e));
            }
        //}

    }
}
